package vuelta.general.util.web;

import vuelta.general.BaseActivity;
import vuelta.general.R;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class WebViewGiro extends BaseActivity {

	private WebView mWebView;
	private ProgressDialog progressBar;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webview);
		initToolbar();

		mWebView = (WebView) findViewById(R.id.webview);
		mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

		mWebView.getSettings().setLoadWithOverviewMode(true);
		mWebView.getSettings().setUseWideViewPort(true);
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.getSettings().setDomStorageEnabled(true);
		mWebView.getSettings().setSupportZoom(true); // Zoom Control on web (You
														// don't need this
		// if ROM supports Multi-Touch
		mWebView.getSettings().setBuiltInZoomControls(true); // Enable
																// Multitouch if
																// supported by
																// ROM
		mWebView.getSettings()
				.setUserAgentString(
						"Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; BOLT/2.800) AppleWebKit/534.6 (KHTML, like Gecko) Version/5.0 Safari/534.6.3");

		String url = getIntent().getStringExtra("url");

		// final AlertDialog alertDialog = new
		// AlertDialog.Builder(this).create();

		progressBar = ProgressDialog.show(WebViewGiro.this, "Wait",
				"Loading...");
		progressBar.setCancelable(true);
		mWebView.setWebViewClient(new WebViewClient() {
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				Toast.makeText(WebViewGiro.this, description,
						Toast.LENGTH_SHORT).show();
			}

			public boolean shouldOverrideUrlLoading(WebView view, String url) {
//				Log.i("Error webView", "Processing webview url click...");
				view.loadUrl(url);
				return true;
			}

			public void onPageFinished(WebView view, String url) {
//				Log.i("Error webView", "Finished loading URL: " + url);
				if (progressBar.isShowing()) {
					progressBar.dismiss();
				}
			}
		});

		mWebView.loadUrl(url);
	}

}